package net.yambal.RTM.Utilty
{
	import com.adobe.utils.DateUtil;
	
	import mx.formatters.DateFormatter;
	
	public class RTMDateUtil
	{
		public function RTMDateUtil()
		{
		}
		
		/**
		 * W3C形式のタイムスタンプをDateにパースする
		 **/
		static public function DateParce(w3c:String):Date{
			if(w3c.length == 0){
				return null;
			}
			
			var ret:Date;
			try{
				ret = DateUtil.parseW3CDTF(w3c);
			}catch (e:Error){
				ret = null;
			}
			
			return ret;
		}
		
		static public function to8601(d:Date):String{
			var df:DateFormatter = new DateFormatter();
			df.formatString = "YYYY/MM/DDTHH:MM:SS";

			var off_tm:int = d.getTimezoneOffset();
			var off_h:int = Math.floor(off_tm/60);
			var off_h_s:String = RTMStringUtil.buryLeft(Math.abs(Math.floor(off_tm/60)), "0", 2);
			if(off_h > 0){
				off_h_s = "+" + off_h_s;
			}else{
				off_h_s = "-" + off_h_s;
			}
			
			var off_m_s:String = RTMStringUtil.buryLeft(Math.abs(off_tm - (off_h * 60)), "0", 2);
			
			
			return df.format(d) + off_h_s + ":" + off_m_s;
		}

	}
}